-------------------------------------------------------------------------------
---! 对外接口
---! 数据库操作方法
-------------------------------------------------------------------------------
FILE_D = {}

function FILE_D:write_common_content(path, name, branch, content)
    path = path or ""
    name = name or ""
    branch = branch or ""
    content = content or ""

    local rpc = {}
    rpc.path = tostring(path)
    rpc.name = tostring(name)
    rpc.branch = tostring(branch)
    rpc.content = tostring(content)
    rpc.method = "write_common_content"
    local ok = THREAD_D:send("database", rpc)
    return ok
end

function FILE_D:read_common_content(path, name, branch)
    path = path or ""
    name = name or ""
    branch = branch or ""

    local rpc = {}
    rpc.path = tostring(path)
    rpc.name = tostring(name)
    rpc.branch = tostring(branch)
    rpc.method = "read_common_content"
    local ok, reply = THREAD_D:send("database", rpc)
    if not ok then
        return false
    end

    if reply then
        return true, reply.content
    end
end

function FILE_D:read_common_data(method, ...)
    local rpc = {}
    rpc.method = method .. ".load"
    rpc.data = table.pack(...)
    local ok, reply = THREAD_D:send("database", rpc)
    if not ok then
        return false
    end
    return true, reply
end

function FILE_D:update_common_data(method, ...)
    local rpc = {}
    rpc.method = method .. ".update"
    rpc.data = table.pack(...)
    local ok, reply = THREAD_D:send("database", rpc)
    if not ok then
        return false
    end
    return true, reply
end
